package Classic150;

public class 长度最小的子数组 {
    /*
        双指针滑动窗口
     */
    public int minSubArrayLen(int target, int[] nums) {
        int res = Integer.MAX_VALUE;
        int left = 0, right = 0;
        int sum = 0;
        while (left < nums.length) {
            if (sum < target) {
                if (right >= nums.length) break;
                sum += nums[right++];
            } else {
                res = Math.min(res, right - left);
                sum -= nums[left++];
            }
        }
        return res == Integer.MAX_VALUE ? 0 : res;
    }
}
